//
//  NSDictionary+utils.m
//  helper
//
//  Created by huangyi on 12-11-7.
//  Copyright (c) 2012年 huangyi. All rights reserved.
//

#import "NSDictionary+utils.h"
#import "NSData+utils.h"
#import "NSArray+utils.h"

@implementation NSDictionary (utils)

-(NSData*)jsonData{
    NSData *data=nil;
    NSError *error=nil;
    data=[NSJSONSerialization dataWithJSONObject:self options:0 error:&error];
    if (error) {
        NSLog(@"%@",error.description);
    }
    return data;
}
-(NSString*)jsonString{
    NSData* data=[self jsonData];
    return data.stringValue;
}

-(NSString*)toString{
    NSMutableArray *strings=[NSMutableArray array];
    NSArray *keys=self.allKeys;
    for (NSString *k in keys) {
        NSMutableString *string=[NSMutableString string];
        [string appendString:k];
        [string appendString:@"="];
        NSString *v=[[self valueForKey:k] stringValue];
        if (v) {
            [string appendString:v];
        }
        [strings addObject:string];
    }
    return [strings componentsJoinedByString:@"&"];
}

@end
